package com.example.test3;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;

public class Demo3 {
    public static void main(String[] args) {
        List<Person> list = new ArrayList<>();
        list.add(new Person("1001", "emp1", 21));
        list.add(new Person("1002", "emp2", 19));
        list.add(new Person("1003", "emp3", 25));
        list.add(new Person("1004", "emp4", 22));
        /*
        // 普通排序
        list.sort(new Comparator<Person>() {
            @Override
            public int compare(Person o1, Person o2) {
                return o1.getAge() - o2.getAge();
            }
        });
         */
        /*
        // lambda表达式排序
        list.sort((o1, o2) -> o1.getAge() - o2.getAge());
         */
        // 对象引用
        list.sort(Comparator.comparingInt(Person::getAge));
        for (Person person : list) {
            System.out.println(person);
        }
    }
}
